#include "scheduler/parallel_scheduler.h"
#include "../policy/policy_factory.h"
#include "../policy/behavior_tree/behavior_tree_fallback_policy.h"
#include "../policy/behavior_tree/behavior_tree_parallel_policy.h"

namespace scheduler
{
ParallelScheduler::ParallelScheduler(const std::string &name)
    : AbstractScheduler(name)
{
    schedule_policy_ = policy::PolicyFactory<policy::BehaviorTreeParallelPolicy>::createPolicy(name + "_policy");
}
bool ParallelScheduler::setTask(const task::AbstractTaskConstPtr &task)
{
    EASE_ERROR("parallel scheduler cannot set task");
    throw std::runtime_error("parallel scheduler cannot set task");
}
bool ParallelScheduler::setScheduler(const AbstractSchedulerConstPtr &scheduler)
{
    EASE_ERROR("parallel scheduler cannot set scheduler");
    throw std::runtime_error("parallel scheduler cannot set scheduler");
}
void ParallelScheduler::setSuccessThreshold(int count)
{
    auto policy = dynamic_cast<policy::BehaviorTreeParallelPolicy *>(schedule_policy_.get());
    if (nullptr == policy)
    {
        throw std::runtime_error("parallel scheduler policy case fail");
    }
    policy->setSuccessThreshold(count);
}
ParallelScheduler::~ParallelScheduler() = default;
}
